WWL.togglebutton = function ( name )
{
	var btn = new WWL.button ( name );

	btn.type = "togglebutton";
	btn.selected = false;

	btn.to_string = function ()
	{
		var s = '', id;
		var mode = null;

		s = '<div class="wwl_' + this.type + '" id="' + this.id + '"';
		s += this.mk_events ();
		s += '><div id="' + this.id + ':content" ';

		if ( this.tooltip ) s += ' title="' + this.tooltip + '"';


		if ( this._is_disabled )
			mode = "disabled";
		else if ( this.selected )
			mode = "selected";

                s += ' class="' + WWL.mk_class_str ( this, mode ) + '">';
		s += this.label;
                s += '</div></div>';

		return s;
	};

	btn.select = function ( set_selected )
	{
		this.selected = set_selected;
		this.render ();
	};

	btn._int_events [ 'over' ]     = function ( widget, div ) { WWL.button._set_class ( widget, div, "hover" + ( btn.selected ? "_selected" : "" ) ); };
	btn._int_events [ 'btn_down' ] = function ( widget, div ) { WWL.button._set_class ( widget, div, "click" + ( btn.selected ? "_selected" : "" ) ); };
	btn._int_events [ 'btn_up' ]   = function ( widget, div ) { WWL.button._set_class ( widget, div, "hover" + ( btn.selected ? "_selected" : "") ); }; 
	btn._int_events [ 'click' ]    = function ( widget, div ) { btn.select ( ! btn.selected ); };
	btn._int_events [ 'out' ]      = function ( widget, div ) { WWL.button._set_class ( widget, div, ( btn.selected ? "selected" : "" ) ); };


	return btn;
};
